package com.lwt.mvc.handler;

import com.lwt.entity.Admin;
import com.lwt.service.api.AdminService;
import com.lwt.util.TongchouUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Author Li Weitong
 * @Date 2021/1/14 11:08
 */
@Controller
public class TestHandler {
    private Logger logger = LoggerFactory.getLogger(TestHandler.class);


    @Autowired
    private AdminService adminService;

    @RequestMapping("/testssm")
    public String testssm(ModelMap modelMap){
        List<Admin> list = adminService.getAllAdmin();

        System.out.println(1/0);
        
        modelMap.addAttribute("adminList",list);
        return "success";
    }

    @ResponseBody
    @RequestMapping("/sendarray")
    public String testSendArray(@RequestBody List<Integer> array, HttpServletRequest req){

        boolean judgeRequestType = TongchouUtil.judgeRequestType(req);
        logger.debug("是ajax请求吗："+judgeRequestType);

//        System.out.println(10/0);

        for (Integer integer : array) {
            logger.debug("数组中的数为"+integer);
        }
        return "success";
    }
}
